package com.lam.code.service.impl;

import com.lam.code.base.BaseServiceImpl;
import com.lam.code.configuration.datasource.DataSource;
import com.lam.code.configuration.datasource.DataSourceType;
import com.lam.code.entity.User;
import com.lam.code.mapper.UserMapper;
import com.lam.code.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lam
 * @description 測試HelloService
 * @date 2019/9/29 22:43
 */
//@Service
@Slf4j
public class HelloServiceImpl extends BaseServiceImpl<UserMapper,User> implements HelloService {
    @Transactional
    @Override
    public void saveUser(User user) {
        if (user.getId() != null){
            this.mapper.updateById(user);
        }else{
            this.mapper.insert(user);
        }
    }

    @Override
    public List<User> getUser() {
        return this.mapper.selectList(null);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<User> getUser2() {
        log.info("getUser2....");
        return this.mapper.selectList(null);
    }
}
